#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#define eps 1e-8
#define MAXARC 1000
using namespace std;
#define MS 10000010
char zf[MS],ch[MS];
struct SJd
{
    int ty,tm;
    double px,py,hd;
}sz[10000];
bool operator<(const SJd&a,const SJd&b)
{
    if(a.tm!=b.tm)
        return a.tm<b.tm;
    return a.hd>b.hd;
}
double W[10000];int cn[1000010],cc[1000010],typ,bpm;
bool tap[1000010][5],ho[5][1000010];
bool addtap(int tm,int w)
{
    if(tap[tm][w]||ho[w][tm])
    {
        int a[5],b=0;
        for(int x=1;x<=4;x++)
            if(!tap[tm][x]&&!ho[x][tm])
                a[b++]=x;
        if(b==0)return 0;
        w=a[rand()%b];
    }
    printf("(%d,%d);\n",tm,w);
    tap[tm][w]=1;
    return true;
}
double getbpm(int le)
{
    for(int i=0;i<le-3;i++)
    {
        if(zf[i]=='b'&&zf[i+1]=='p'&&zf[i+2]=='m')
        {
            int w=i+5,k=0;
            while(zf[w]!=',')
                ch[k++]=zf[w++];
            ch[k]=0;double bpm;
            sscanf(ch,"%lf",&bpm);
            return bpm;
        }
    }
    return -1;
}
int co[10000],nx[10000],snk[300010][3];
int getcol(int l,int r,double w,double lw)
{
    bool bb[3]={0};
    for(int i=l;i<=r;i++)
        for(int j=0;j<3;j++)
            bb[j]|=snk[i][j];
    int rt=(lw<0.5?0:1);
    if(!bb[rt])return rt;
    rt=0;
    while(rt<2&&bb[rt])rt+=1;
    return rt;
}
void setcol(int l,int r,int c)
{
    for(int i=l;i<r;i++)
        snk[i][c]=1;
}
bool gen[10000];int fli[10000];
void getpos(double w,double&x,double&y,int tm,int co)
{
    if(typ==2)
    {
        x=w;y=1;
        if(x<0){y=0.85-(-x)*1.7;x=-x;}
        if(x>1){y=0.85-(x-1)*1.7;x=2-x;}
        
        /*double t=500;x+=tm/t+co/2.0;//随机蛇
        while(x<-0.5||x>1.5)
        {
            if(x>1.5)x=3-x;
            else x=-1-x;
        }
        if(x<0)y=1-(-x)*2;
        if(x>1)y=1-(x-1)*2;
        y=y*(1-pow(cos(tm),4));*/
    }
    else if(typ==3||typ==1)
    {
        x=w,y=1;
        if(x>1)x=1;
        if(x<0)x=0;
    }
    else if(typ==4)
    {
        w=w*9/7-1.0/7;x=w;y=1;
        if(x<-0.1){y=0.9-(-0.1-x)*2;x=-x-0.2;}
        if(x>1.1){y=0.9-(x-1.1)*2;x=2.2-x;}//略微超界
    }
}
void addarc(int t1,int t2,double w1,double w2,int c)
{
    double x1,y1,x2,y2;
    getpos(w1,x1,y1,t1,c);
    getpos(w2,x2,y2,t2,c);
    char ch[8][5]={"b","s","si","so","sisi","siso","soso","sosi"};
    printf("arc(%d,%d,%.2lf,%.2lf,%s,%.2lf,%.2lf,%d,none,false);\n",t1,t2,x1,x2,ch[rand()%8],y1,y2,c);
}
struct Sky
{
    int tm;double x,y;Sky(){}
    Sky(int Tm,double X,double Y)
    {
        tm=Tm;x=X;y=Y;
    }
}sk[10000];int sks=0,de[10000];
bool check(const Sky&a,const Sky&b)
{
    if(a.tm==b.tm)return 0;
    double dx=fabs(b.x-a.x)/(b.tm-a.tm);
    double dy=fabs(b.y-a.y)/(b.tm-a.tm);
    return dx<=0.0025&&dy<=0.0015;
}
bool operator<(const Sky&a,const Sky&b)
{
    if(a.tm!=b.tm)
        return a.tm<b.tm;
    return a.x<b.x;
}
bool del[10000];int fa[10000];
int main()
{
    freopen("2.aff","w",stdout);
    printf("AudioOffset:0\n-\ntiming(0,100.00,4.00);\n");
    char fi[20];
    cerr<<"文件名称：";
    scanf("%s",fi);
    double kk=2.5,bb=0.75,fw=0.3,e=0.75,f=0.125;
    cerr<<"note位置（建议2或3）：";
    int die;scanf("%d",&typ);
    if(typ==1)
        {kk=1.5;bb=0.25;fw=0.4;e=1;f=0;}
    else if(typ==3)
        {kk=28.0/15;bb=13.0/30;}
    if(typ==3)
    {
        int t;
        cerr<<"蛇是否有高度变化（0无，1有）：";
        scanf("%d",&t);typ+=t;
    }
    int nosnake,lnk,ty4,mintm;
    cerr<<"黄键解析类型（0蛇，1蓝键，2删除）：";
    scanf("%d",&nosnake);
    if(nosnake==1)
    {
        cerr<<"最小间隔：";
        scanf("%d",&mintm);
    }
    if(!nosnake)
    {
        cerr<<"蛇必须连接：";
        scanf("%d",&lnk);
    }
    cerr<<"粉键解析类型（0垂直双押，1叠键，2短蛇，3蓝键）：";
    scanf("%d",&ty4);
    if(ty4==1)
    {
        cerr<<"叠键速度：";
        scanf("%d",&die);
    }
    int mintd;cerr<<"最小天地间隔（建议70~90）：";
    scanf("%d",&mintd);
    freopen(fi,"r",stdin);
    scanf("%s",zf);
    int le=strlen(zf),n=0,la=0,lst=-1e9;
    bpm=getbpm(le);
    double rat=60000.0/bpm/320.0,lw=-1;int lt=0;
    for(int i=0;i<le-4;i++)//读取数据
    {
        if(zf[i]=='t'&&zf[i+1]=='y'&&zf[i+2]=='p'&&zf[i+3]=='e')
        {
            int w=i+6,k=0;
            while(zf[w]!='}')
                ch[k++]=zf[w++];
            ch[k]=0;
            int ty,tm;double px,py,hd,spd;
            sscanf(ch,"%d,\"time\":%d,\"positionX\":%lf,\"holdTime\":%lf,\"speed\":%lf,\"floorPosition\":%lf",&ty,&tm,&px,&hd,&spd,&py);
            SJd t;
            t.ty=ty;t.tm=floor(tm*10*rat+0.5);
            t.px=px;t.py=py;t.hd=hd*10*rat;
            //if(n>0&&t.tm-sz[n-1].tm>100)t.ty=2;
            sz[n++]=t;cn[t.tm]+=1;
            if(fabs(t.hd)<eps)//三押
            {
                //if(cc[t.tm]>=2)sz[n-1].ty=-1;
                //else cc[t.tm]
                /*else
                {
                    for(int z=t.tm;z<=t.tm+t.hd;z++)
                        cc[z]+=1;
                }*/
                cc[t.tm]+=1;
            }
            if(t.ty==2)cn[t.tm]=10;
        }
    }
    sort(sz,sz+n);
    if(nosnake==0)//删去太密集的黄键
    //if(0)
    {
        for(int s=0;s<(n+19)/20;s++)//20个一组
        {
            double xl=1e9,xr=-1e9;
            for(int i=s*20;i<n&&i<s*20+20;i++)
            {
                double x=sz[i].px;
                if(x<xl)xl=x;if(x>xr)xr=x;
            }
            if(fabs(xr-xl)<eps)
                xl-=0.01,xr+=0.01;
            for(int i=s*20;i<n&&i<s*20+20;i++)
                W[i]=(sz[i].px-xl)/(xr-xl)*e+f;
        }
        double w1,w2;int t1=-1,t2=-1,i1,i2;
        for(int i=0;i<n;i++)
        {
            if(sz[i].ty!=2)continue;
            double w=W[i];
            if(t1>=0&&t2>=0)
            {
                if(fabs(w1-w)<0.01)
                    gen[i2]=fabs(w1-w2)<0.01;
                else
                {
                    double K=(sz[i].tm-t1)/(w-w1),B=t1-w1*K;
                    double tt=K*w2+B;
                    if(fabs(tt-t2)<30)
                    {
                        cerr<<"被删除的黄键："<<i2<<endl;
                        gen[i2]=1;
                    }
                }
                if(gen[i2])
                {
                    fa[i2]=(!gen[i1]?i1:fa[i1]);
                    fa[i]=fa[i2];del[i2]=1;
                }
            }
            i1=i2;w1=w2;t1=t2;
            i2=i;w2=w;t2=sz[i].tm;
        }  
    }
    for(int i=0;i<n;i++)co[i]=-1;
    int tt=1,czsy=0;
    for(int s=0;s<(n+19)/20;s++)//20个一组
    {
        double xl=1e9,xr=-1e9;
        for(int i=s*20;i<n&&i<s*20+20;i++)
        {
            double x=sz[i].px;
            if(x<xl)xl=x;
            if(x>xr)xr=x;
        }
        if(fabs(xr-xl)<eps)
            xl-=0.01,xr+=0.01;
        for(int i=s*20;i<n&&i<s*20+20;i++)
        {
            if(sz[i].ty==-1)continue;
            if(nosnake==1&&sz[i].tm>lst&&sz[i].tm-lst<mintm)continue;
            lst=sz[i].tm;
            double x=sz[i].px;int h=floor(sz[i].hd+0.5);
            double ww=(x-xl)/(xr-xl)*e+f;
            W[i]=ww;
            int w=int(ww*4-eps)+1,tm=sz[i].tm;
            if(w<1)w=1;if(w>4)w=4;
            //if(sz[i].ty==4&&ty4==3)sz[i].ty=1;
            //h=0;
            if(sz[i].ty==4)//粉
            {
                /*if(i&&sz[i-1].ty==4&&sz[i-1].tm!=sz[i].tm)//相邻粉色 --> Arc
                    printf("arc(%d,%d,%.2lf,%.2lf,s,1.00,1.00,%d,none,false);\n",sz[i-1].tm,tm,W[i-1]*kk-bb,ww*kk-bb,0);*/
                int z=-1;
                for(int j=i+1;j<n&&sz[j].tm<=sz[i].tm+150;j++)//太近的变成蛇
                    if(sz[j].tm>sz[i].tm&&sz[j].ty==4)
                        {z=j;break;}
                if(z!=-1)fli[z]=i;
                else if(!fli[i])
                {
                    if(ty4==0)//垂直双押
                    {
                        bool rt=addtap(tm,w);
                        if(!rt||cn[tm]<=1)
                        {
                            double z=ww*kk-bb;
                            if(z<-0.1)z=-0.1;if(z>1.1)z=1.1;
                            printf("arc(%d,%d,%.2lf,%.2lf,s,1.00,1.00,0,none,true)[arctap(%d)];\n",tm,tm+1,z,z,tm),sk[sks++]=Sky(tm,ww*kk-bb,1);
                            if(rt)czsy+=1;
                        }
                    }
                    else if(ty4==1)
                        addtap(tm,w),addtap(tm+240000/die/bpm,w);
                    else if(ty4==2)
                    {
                        int cd=80,co=getcol(tm,tm+cd,ww,ww);setcol(tm,tm+cd,co);
                        if(ww*kk-bb<-0.2)ww=(bb-0.2)/kk;
                        if(ww*kk-bb>1.2)ww=(bb+1.2)/kk;
                        int fx=(ww>0.5?0:1);
                        if(fx==0)
                        {
                            printf("arc(%d,%d,%.2lf,%.2lf,s,1.00,0.70,%d,none,false);\n",tm,tm+cd/2,ww*kk-bb,ww*kk-bb-0.15,co);
                            printf("arc(%d,%d,%.2lf,%.2lf,s,0.70,0.40,%d,none,false);\n",tm+cd/2,tm+cd,ww*kk-bb-0.15,ww*kk-bb-0.3,co);
                        }
                        else
                        {
                            printf("arc(%d,%d,%.2lf,%.2lf,s,1.00,0.70,%d,none,false);\n",tm,tm+cd/2,ww*kk-bb,ww*kk-bb+0.15,co);
                            printf("arc(%d,%d,%.2lf,%.2lf,s,0.70,0.40,%d,none,false);\n",tm+cd/2,tm+cd,ww*kk-bb+0.15,ww*kk-bb+0.3,co);
                        }
                        sk[sks++]=Sky(tm,ww*kk-bb,1);
                    }
                }
                if(fli[i])
                {
                    z=fli[i];int co=getcol(sz[z].tm,sz[i].tm,ww,ww);
                    setcol(sz[z].tm,sz[i].tm,co);
                    printf("arc(%d,%d,%.2lf,%.2lf,s,0.00,0.00,%d,none,false);\n",sz[z].tm,tm,W[z]*kk-bb,ww*kk-bb,co);
                    sk[sks++]=Sky(tm,ww*kk-bb,0);
                }
            }
            else if(sz[i].ty==2&&!nosnake)//黄
            {
                if(gen[i])continue;
                int z=-1;
                if(lnk||(i&&sz[i-1].ty==2))
                {
                    if(fa[i])z=fa[i];
                    else
                    {
                        for(int j=i-1;j>=0;j--)
                        {
                            if(!del[j]&&sz[j].ty==2&&nx[j]==0&&fabs(W[i]-W[j])<0.3*e&&sz[j].tm<sz[i].tm)
                                {z=j;break;}
                        }
                    }
                }
                if(z!=-1&&(fa[i]||sz[i].tm-sz[z].tm<=MAXARC))
                {
                    nx[z]=1;co[i]=co[z];
                    if(co[i]==-1)co[i]=getcol(sz[z].tm,tm,ww,W[z]);
                    /*if(co[i]==2||snk[tm][co[i]]||snk[sz[z].tm][co[i]])//
                        sz[i].ty=1;
                    else
                    {*/
                        addarc(sz[z].tm,tm,W[z]*kk-bb,ww*kk-bb,co[i]);
                        setcol(sz[z].tm,tm,co[i]);gen[z]=gen[i]=1;
                    //}
                }
            }
            if(sz[i].ty==1||sz[i].ty==3||(sz[i].ty==4&&ty4==3&&!fli[i])||(sz[i].ty==2&&nosnake==1))//蓝
            {
                if(h)//长条
                {
                    if(!ho[w][tm])
                    {
                        printf("hold(%d,%d,%d);\n",tm,tm+h,w);
                        for(int t=tm;t<=tm+h;t++)ho[w][t]=1;
                    }
                }
                else
                {
                    if((fabs(ww*4-(w-1+0.5))<fw||(i>0&&tm!=sz[i-1].tm&&tm-sz[i-1].tm<=50)||(i+1<n&&tm!=sz[i+1].tm&&sz[i+1].tm-tm<=mintd)||sz[i].ty==2)&&cc[tm]<=2)
                        addtap(tm,w),la=w;
                    else
                    {
                        if(i&&tm-lt>130&&fabs(ww-lw)>0.1)tt=tt%5+1;
                        double h=tt*0.2;
                        printf("arc(%d,%d,%.2lf,%.2lf,s,%.2lf,%.2lf,0,none,true)[arctap(%d)];\n",tm,tm+1,ww*kk-bb,ww*kk-bb,h,h,tm),sk[sks++]=Sky(tm,ww*kk-bb,h);
                        lw=ww;lt=tm;
                    }
                }
            }
        }
    }
    for(int i=0;i<n;i++)//补键
    {
        if(sz[i].ty==2&&!gen[i]&&!nosnake)
        {
            double ww=W[i];int tm=sz[i].tm;
            int w=int(ww*4-eps)+1;
            if(fabs(ww*4-(w-1+0.5))<fw)
                addtap(tm,w);
            else
                printf("arc(%d,%d,%.2lf,%.2lf,s,%.2lf,%.2lf,0,none,true)[arctap(%d)];\n",tm,tm+1,ww*kk-bb,ww*kk-bb,0.5,0.5,tm),sk[sks++]=Sky(tm,ww*kk-bb,0.5);
        }
    }
    sort(sk,sk+sks);
    while(1)//黑线
    {
        int w=0;
        while(w<sks&&de[w])w+=1;
        if(w==sks)break;
        printf("arc(%d,%d,%.2lf,%.2lf,s,%.2lf,%.2lf,0,none,true);\n",max(sk[w].tm-4000,0),sk[w].tm,sk[w].x,sk[w].x,sk[w].y,sk[w].y);
        de[w]=true;
        while(1)
        {
            int t=w+1;
            while(t<sks&&sk[t].tm<=sk[w].tm+8000&&(de[t]||!check(sk[w],sk[t])))t+=1;
            if(t==sks||sk[t].tm>sk[w].tm+8000)break;
            printf("arc(%d,%d,%.2lf,%.2lf,b,%.2lf,%.2lf,0,none,true);\n",sk[w].tm,sk[t].tm,sk[w].x,sk[t].x,sk[w].y,sk[t].y);
            de[t]=true;w=t;
        }
    }
    if(ty4==0)cerr<<"共有"<<czsy<<"个垂直双押。"<<endl;
    return 0;
}